********************************************************************************
/*
Run all programs from this master do file.

IMPORTANT: In section 1.1.b. of this do file, set the global master_file_path to the file path of the README file on your computer
*/
********************************************************************************
* 1. Setup
********************************************************************************
version 16.1
clear all
macro drop _all
set more off
set maxvar 32000
cap log close
set type float


*------------------------------------------------------------------------------*
* 1.1 a. Install external code packages - comment out if already installed
*------------------------------------------------------------------------------*
/*
ssc install reghdfe, replace 
ssc install estout, replace 
ssc install texdoc, replace
ssc install boottest, replace
ssc install winsor2, replace
ssc install unique, replace
ssc install ftools, replace
ssc install egenmore, replace
ssc install tuples, replace
ssc install touch. replace
*/


*------------------------------------------------------------------------------*
* 1.1.b. Set file path
*------------------------------------------------------------------------------*
		
* Set the global master_file_path to the file path of the README file on your computer

global username = c(username)
global dropbox "/Users/${username}/Dropbox"
global master_file_path "${dropbox}/Engel_GFT/replication_files"

*------------------------------------------------------------------------------*
* 1.1.c. Folders
*------------------------------------------------------------------------------*

** Data Folders
global data_folder "${master_file_path}/data"

** Code Folders
global do_files_folder "${master_file_path}/do_files"

** Output Folders
global output_folder "${master_file_path}/output"

** Create a folder on your PC (we call it "Delete") that is not uploading to a remote server (such as within a Dropbox folder) since this will trip some of the code that creates and deletes temporary files in quick succession:
global dump "C:/Delete"

********************************************************************************
* 2. Construct main datasets: 
********************************************************************************	
*Clean up R43 NSS:
if 1==2{
do "${do_files_folder}/1.R43_new_Stata_processed_V2.do"
*This generates file:
* /data/intermediate_data/consumption_items_43.dta
}

*Clean up R55 NSS:
if 1==2{
do "${do_files_folder}/2.R55_Stata_processed_V2.do"
*This generates file:
* /data/intermediate_data/consumption_items_55.dta
}

*Merge in round 43 to 55 item and district concordances:
if 1==2{
do "${do_files_folder}/3.concorded43.do"
do "${do_files_folder}/4.concorded55.do"
*This generates files:
*concorded_consumption_items43.dta
*concorded_consumption_items55.dta
}

*Add in 34 i good level definitions, define deaton drops variable, define mpce flag variable:
if 1==2{
do "${do_files_folder}/5.cleaned_expenditures_V4_4355.do"
*This step creates two files: 
*a) Expenditures at the item level:
*expenditures_item_level_R43R55_i_groupsV1.dta
*b) Expenditures collapsed to the 34 i good level:
*expenditures_R43R55_i_groupsV1_D.dta
}

if 1==2{
do "${do_files_folder}/6.dofile_G_groups.do"
*This step creates:
*G_Groupings_108.dta
}

*Create the household shares database:
if 1==2{
do "${do_files_folder}/6.Assemble_all_data_04_multipleGs.do"
*This step creates:
*expenditures_R43R55_i_groupsV1_D.dta
*hh_shares_43_55V1_DM_G108_15_rural.dta
*item_codes
}

*Create the database with change in log prices at the i level:
if 1==2{
do "${do_files_folder}/7.CPI_43_55_V3.do"
*This step creates:
*d_ln_p_goods_i_55_43.dta

do "${do_files_folder}/7.CPI_43_55_V3_decile.do"
*This step creates:
*d_ln_p_goods_i_55_43_decile.dta
}

*Create database with price indices at the district by decile level:
if 1==2{
do "${do_files_folder}/8.CPI_43_55_V4.do"
*This step creates files:
*CPI_district_X_decile_level_V4.dta
}

*Create bootstrap databases for CPI graph:
if 1==2{
do "${do_files_folder}/9.CPI_43_55_V4_bootstrap.do"
*This step creates files:
*CPI_district_level_V4.dta
*bootstrap CPI files
}

********************************************************************************
* 3. Conduct analyses 
********************************************************************************	
if 1==2{
do "${do_files_folder}/10.Master_engel_lpoly_v1_bootstrap.do"
}

if 1==2{
do "${do_files_folder}/11.do_file_Figure_6_replication.do"
}

if 1==2{
do "${do_files_folder}/12.Quasi_separability_panel_A.do"
}

if 1==2{
do "${do_files_folder}/13.Quasi_separability_panel_B.do"
}
